package com.areaCalc;

import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

class MyOverlay extends Overlay{
	
	Paint mPaint;
	Path path;
	Projection projection;
	GeoPoint oldPoint;
	GeoPoint newPoint;
	List<GeoPoint> points;
	boolean isArea;
	
	
    public MyOverlay(MapView mapView, List<GeoPoint> points, boolean isArea){
    	projection = mapView.getProjection();
    	this.points = points;
    	this.isArea= isArea;

    }   

    public void draw(Canvas canvas, MapView mapv, boolean shadow){
        super.draw(canvas, mapv, shadow);

        mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.GREEN);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        
        for (int i = 0; i < points.size(); i++) {
        	
        	Point p1 = new Point();
            Point p2 = new Point();

            path = new Path();

            GeoPoint gP1 = points.get(i);
            GeoPoint gP2;
            if(i+1 < points.size()) {
            	gP2 = points.get(i + 1);
            }else {
            	if(isArea) {
            		gP2 = points.get(0);
            	}else {
            		gP2 = gP1;
            	}
            }
            
    		projection.toPixels(gP1, p1);
            projection.toPixels(gP2, p2);

            path.moveTo(p2.x, p2.y);
            path.lineTo(p1.x,p1.y);
            canvas.drawPath(path, mPaint);
        }
        

        
    }
}